<template>
	<view class="box">
		<uNavbar title="修改登录密码" bgColor="transparent"></uNavbar>
		<view class="title">
			<!-- 当前手机号：13515545699 -->
		</view>
		<view class="main_item">
			<view class="main_item_title">
				原密码
			</view>
			<input type="password" :value="oldpass" placeholder="请输入原密码" @input="getoldpass" />
		</view>
		<view class="main_item">
			<view class="main_item_title">
				新密码
			</view>
			<input type="password" :value="pass1" placeholder="请输入新密码" @input="getpass1" />
		</view>
		<view class="main_item">
			<view class="main_item_title">
				确认密码
			</view>
			<input type="password" :value="pass2" placeholder="请输入确认密码" @input="getpass2" />
		</view>
		<view class="btn" @click="amend" >
			确定
		</view>
	</view>
</template>

<script>
	import {editPassword} from "../../api/setting.js";
 	export default {
		data() {
			return {
				oldpass:"",
				pass1:"",
				pass2:"",
				canClick:true
			}
		},
		computed:{
			 isAlphaNumeric() {
			  const pattern = /^[A-Za-z0-9]+$/;
			  return pattern.test(this.pass1);
			}
		},
		methods: {
			amend(){
				if(!this.isAlphaNumeric){
					uni.$u.toast("账号仅支持字母和数字");
				}else{
					if (!this.canClick) {
					        return;
					      }
					this.canClick = false;
					editPassword({
						old_password:this.oldpass,
						password:this.pass1,
						re_password:this.pass2
					}).then(res=>{
						console.log(res)
						if(res.code==1){
							uni.$u.toast(res.msg+"请重新登录");
							setTimeout(()=>{
								uni.reLaunch({
									url:"/pages/login/login"
								})
							},1500)
							
							uni.removeStorageSync("token")
							
						}else{
							uni.$u.toast(res.msg);
						}
						 setTimeout(() => {
						        this.canClick = true;
						      }, 1000); // 设定一个点击间隔，防止频繁点击
					})
				}

			},
			getoldpass(e){
				this.oldpass=e.detail.value
			},
			getpass1(e){
				this.pass1=e.detail.value
			},
			getpass2(e){
				this.pass2=e.detail.value
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		width: 750rpx;
		height: 100vh;
		background-color: #E0DDDA;
	}

	.title {
		width: 700rpx;
		margin-top: 40rpx;
		font-weight: 400;
		font-size: 32rpx;
		color: #333;
		margin-left: 50rpx;
	}
	/deep/.uni-input-input{
		color: #333;
	}
	.main_item {
		width: 750rpx;

		.main_item_title {
			font-weight: 400;
			font-size: 30rpx;
			color: #333;
			margin-left: 50rpx;
			margin-top: 70rpx;
		}

		>input {
			margin: 0 auto;
			margin-top: 40rpx;
			width: 638rpx;
			height: 50rpx;
			font-weight: 300;
			font-size: 30rpx;
			color: #A6A5AF;
			border-bottom: 2rpx solid #CFC4B7;
		}
	}

	.binding {
		width: 90%;
		margin: 0 auto;
		padding: 18rpx 0;
		border-radius: 60rpx;
		// background: #2B2749;
		/* border-bottom: 1rpx solid #5a5a5a70; */
	}

	/deep/.u-button--success {
		background: none !important;
		border: none !important;
		color: #FF2CDF !important;
	}

	/deep/.u-border {
		border: none;
		border-bottom: 2rpx solid rgba(255, 44, 223, 0.5) !important;
	}

	/deep/.uni-input-wrapper {
		color: #A6A5AF !important;
	}

	/deep/.uni-input-placeholder {
		color: #A6A5AF !important;
	}

	.btn {
		width: 690rpx;
		height: 88rpx;
		background: linear-gradient( 90deg, #AB8E68 0%, #D7BA93 100%);
		border-radius: 332rpx 332rpx 332rpx 332rpx;
		margin: 0 auto;
		margin-top: 50rpx;
		font-weight: 400;
		font-size: 36rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 88rpx;
	}
</style>